home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
60914
/
60914.xpi
/
chrome
/
content
/
select.js
< prev
next >
Wrap
Text File
|
2010-01-20
|
8KB
|
313 lines

var PersonaWindowSelectManager={
setTimeOutId:null,
highlighteds:[],
CTRLpressed:false,
SHIFTpressed:false,
lastedited:null,
getSiblings:function (passednode) {
var activenode=passednode;
var siblings=[];
var parentNode=activenode.parentNode;
var queriednode=null;
for (var i=0;i<parentNode.childNodes.length;i++) {
queriednode=parentNode.childNodes[i];
if(queriednode!=activenode) {siblings.push(parentNode.childNodes[i]);}
}
return siblings;
},
changeTotrue:function (event) {
if (event.which == 16) PersonaWindowSelectManager.SHIFTpressed=true;
if (event.which == 17) PersonaWindowSelectManager.CTRLpressed=true;
},
changeTofalse:function (event) {
if (event.which == 16) PersonaWindowSelectManager.SHIFTpressed=false;
if (event.which == 17) PersonaWindowSelectManager.CTRLpressed=false;
},
insideselection:function (nodepassed) {
for (var i=0;i<PersonaWindowSelectManager.highlighteds.length;i++) {
if (nodepassed==PersonaWindowSelectManager.highlighteds[i]) return true;
}
return false;
},
clicklistener:function (event) {
if (event.button==1) {return};
if((PersonaWindowSelectManager.CTRLpressed==true && event.button==2)||(PersonaWindowSelectManager.SHIFTpressed==true&&event.button==2)) return;
if(PersonaWindowSelectManager.CTRLpressed==true&&PersonaWindowSelectManager.SHIFTpressed==true) {
PersonaWindowSelectManager.CTRLpressed=true;
PersonaWindowSelectManager.SHIFTpressed=false;
}
var highlighthas;
if(PersonasWindow.updateModeOn==true) {alert(PersonasWindow.retrieveAppropriateAlertText());event.preventDefault();return;};
var intendednode=PersonasWindow.hasClass(event.target,"serdo") ? event.target.previousSibling : event.target;
PersonasWindow.copystate=false;
PersonasWindow.cutstate=false;
if (PersonaWindowSelectManager.highlighteds.length>0){
if(PersonaWindowSelectManager.highlighteds[0].parentNode.parentNode!=intendednode.parentNode.parentNode){
var highlightedsarrray=[];
for(var i=0;i<document.getElementsByClassName("highlighted").length;i++){
highlightedsarrray.push(document.getElementsByClassName("highlighted")[i]);
}
for (var i=0;i<highlightedsarrray.length;i++) {
PersonasWindow.removeClass(highlightedsarrray[i],"highlighted");
}
PersonaWindowSelectManager.highlighteds=[];
}
}
if (event.button==2) {
if(PersonaWindowSelectManager.insideselection(intendednode)) {return;}
else {highlighthas=true}
}
else {
if (PersonasWindow.hasClass(intendednode,"highlighted")) highlighthas=true;
else highlighthas=false;
}
if(PersonaWindowSelectManager.CTRLpressed!=true) {
var highlightedsarrray2=[];
for(var i=0;i<document.getElementsByClassName("highlighted").length;i++){
highlightedsarrray2.push(document.getElementsByClassName("highlighted")[i]);
}
for (var i=0;i<highlightedsarrray2.length;i++) {
PersonasWindow.removeClass(highlightedsarrray2[i],"highlighted");
}
PersonaWindowSelectManager.highlighteds=[];
}
else {
if (highlighthas) PersonasWindow.removeClass(intendednode,"highlighted");
else {PersonasWindow.addClass(intendednode,"highlighted");}
if(PersonasWindow.hasClass(intendednode,"highlighted")) {PersonaWindowSelectManager.highlighteds.push(intendednode);PersonaWindowSelectManager.lastedited=intendednode;}
else {PersonaWindowSelectManager.arraydelete(intendednode);PersonaWindowSelectManager.lastedited=intendednode;}
return;
}
if (PersonaWindowSelectManager.SHIFTpressed==true) {
var highlightedsarrray3=[];
for(var i=0;i<document.getElementsByClassName("highlighted").length;i++){
highlightedsarrray3.push(document.getElementsByClassName("highlighted")[i]);
}
for (var i=0;i<highlightedsarrray3.length;i++) {
PersonasWindow.removeClass(highlightedsarrray3[i],"highlighted");
}
var parentNode=intendednode.parentNode.parentNode;
var targetindex;
var lasteditedindex;
var direction;
var nowindex;
for (var i=0;i<parentNode.childNodes.length;i++) {
if (intendednode==parentNode.childNodes[i].childNodes[0]) targetindex=i;
if (PersonaWindowSelectManager.lastedited==parentNode.childNodes[i].childNodes[0]) lasteditedindex=i;
}
if (targetindex>lasteditedindex) {
direction="ascending";
nowindex=targetindex;
PersonaWindowSelectManager.highlighteds=[];
while (nowindex>=lasteditedindex){
PersonasWindow.addClass(parentNode.childNodes[nowindex].childNodes[0],"highlighted");
PersonaWindowSelectManager.highlighteds.push(parentNode.childNodes[nowindex].childNodes[0]);
nowindex--;
PersonaWindowSelectManager.lastedited=parentNode.childNodes[targetindex].childNodes[0];
}
return;
}
if (targetindex<lasteditedindex) {
direction="ascending";
nowindex=lasteditedindex;
PersonaWindowSelectManager.highlighteds=[];
while (targetindex<=nowindex){
PersonasWindow.addClass(parentNode.childNodes[nowindex].childNodes[0],"highlighted");
PersonaWindowSelectManager.highlighteds.push(parentNode.childNodes[nowindex].childNodes[0]);
nowindex--;
PersonaWindowSelectManager.lastedited=parentNode.childNodes[targetindex].childNodes[0];
}
return;
}
if (targetindex==lasteditedindex) {
direction="ascending";
nowindex=lasteditedindex;
PersonaWindowSelectManager.highlighteds=[];
while (targetindex<=nowindex){
PersonasWindow.addClass(parentNode.childNodes[nowindex].childNodes[0],"highlighted");
PersonaWindowSelectManager.highlighteds.push(parentNode.childNodes[nowindex].childNodes[0]);
nowindex--;
PersonaWindowSelectManager.lastedited=parentNode.childNodes[targetindex].childNodes[0];
}
return;
}
}
if(!PersonasWindow.hasClass(intendednode,"highlighted")) {
PersonasWindow.addClass(intendednode,"highlighted");
PersonaWindowSelectManager.highlighteds.push(intendednode);
PersonaWindowSelectManager.lastedited=intendednode;
}
},
arraydelete:function (node) {
highlightedscopy=[];
for (var i=0;i<PersonaWindowSelectManager.highlighteds.length;i++){
if (PersonaWindowSelectManager.highlighteds[i]!=node) highlightedscopy.push(PersonaWindowSelectManager.highlighteds[i]);
}
PersonaWindowSelectManager.highlighteds=highlightedscopy;
},
handleDoubleClick:function (event) {
window.clearTimeout(PersonaWindowSelectManager.setTimeOutId);
},
returnindex:function (node) {
var parentNode=node.parentNode;
var targetindex;
var lasteditedindex;
for (var i=0;i<parentNode.childNodes.length;i++) {
if (node==parentNode.childNodes[i]) return i;
}
},
multireturnindex:function () {
var t="";
for (var i=0;i<PersonaWindowSelectManager.highlighteds.length;i++) {
node=PersonaWindowSelectManager.highlighteds[i];
var parentNode=node.parentNode;
for (var b=0;b<parentNode.childNodes.length;b++) {
if (node==parentNode.childNodes[b]) { t+=b+",";}
}
}
return t;
}
}
window.addEventListener("keydown",PersonaWindowSelectManager.changeTotrue,false);
window.addEventListener("keyup",PersonaWindowSelectManager.changeTofalse,false);